home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-06 | 31.0 KB | 873 lines | [TEXT/MPS ] |
- {
- Description of the PrintX array:
- 1 used as Enum value 0 corresponding to A4 format (style Dlg)
- value 1 corresponding to US format (style Dlg)
- value 2 corresponding to Custom format (style Dlg)
- 2 used as Integer Reduce/Enlarge ratio (style Dlg)
- 3 used as Integer Horizontal value for Custom format (style Dlg)
- 4 used as Integer Vertical value for Custom format (style Dlg)
- 5 used as Enum value 0 corresponding to MilliInches unit (style Dlg)
- value 1 corresponding to MilliMeters unit (style Dlg)
- value 2 corresponding to Pixel unit (style Dlg)
- 6 used as Boolean value 0 corresponding to Portrait Orientation (style Dlg)
- value 1 corresponding to LandScape Orientation (style Dlg)
- 7 used as Boolean value 0 corresponding to All pages (job Dlg)
- value 1 corresponding to pages From … To … (job Dlg)
- 8 used as Boolean value 0 corresponding to TEXT saving (job Dlg)
- value 1 corresponding to PICT saving (job Dlg)
- 9 used as Integer signature $5345 "ES"
- 10,11 used as OsType creator used for TEXT saving (option Dlg)
- 12,13 used as OsType creator used for PICT saving (option Dlg)
- 14 used as Boolean value 0 corresponding to Color (job Dlg)
- value 1 corresponding to Black & White (job Dlg)
- 15,16 used as Longint scaling ratio (option Dlg)
- 17 used as Boolean value 0 corresponding to PicComment saving (option Dlg)
- value 1 corresponding to PicComment ignoring (option Dlg)
- 18 not used
- 19 not used
- }
-
- unit MyPDEF_0_DraftMode;
-
- interface
-
- uses MemTypes, QuickDraw, OsIntf, ToolIntf, PackIntf, MacPrint;
-
- {$D+}
- {$R-}
- {$OV-}
-
- type
- MyPrintRec = RECORD
- dirName: Str255;
- dirID: Longint;
- dirVol: Integer;
- fileName: Str255;
- fileRef: Integer;
- textOrPict: Boolean;
- OtherPort: GrafPtr;
- thePict: PicHandle;
- CurPage: Integer;
- cProcs: CQDProcs;
- theTextType,
- thePictType: OsType;
- scaleRatio: Longint;
- END;
- MyPrintPtr = ^MyPrintRec;
-
- function DraftPrOpenDoc(hPrint: THPrint; pPrPort: TPPrPort; pIOBuf: Ptr): TPPrPort;
- procedure DraftPrCloseDoc(pPrPort: TPPrPort);
- procedure DraftPrOpenPage(pPrPort: TPPrPort; pPageFrame: TPRect);
- procedure DraftPrClosePage(pPrPort: TPPrPort);
- procedure DraftPrText(byteCount: Integer; textBuf: Ptr; numer, denom: Point);
- procedure DraftPrLine(newPt: Point);
- procedure DraftPrRect(verb: GrafVerb; r: Rect);
- procedure DraftPrrRect(verb: GrafVerb; r: Rect; ovalWidth, ovalHeight: Integer);
- procedure DraftPrOval(verb: GrafVerb; r: Rect);
- procedure DraftPrArc(verb: GrafVerb; r: Rect; startAngle, arcAngle: Integer);
- procedure DraftPrPoly(verb: GrafVerb; Poly: PolyHandle);
- procedure DraftPrRgn(verb: GrafVerb; Rgn: RgnHandle);
- procedure DraftPrBits(var srcBits: BitMap; var srcRect, dstRect: Rect; mode: Integer; maskRgn: RgnHandle);
- procedure DraftPrComment(kind, dataSize: Integer; dataHandle: Handle);
- procedure ChangeBottleNeck(withColor: Boolean; myPPrPort: TPPrPort; thePrintPtr: MyPrintPtr; withPicComments: Boolean);
- function GetValues(hPrint: THPrint; thePrintPtr: MyPrintPtr): Boolean;
- function GetVolumeRef(theWDRefNum: Integer; VAR theVolRef: Integer; VAR theDirID: Longint): OsErr;
- function CreateDirectory(VAR fName: Str63; theVRefNum: Integer; theDirID: Longint; VAR theNewDirID: Longint): OsErr;
- function OpenWorkingDirectory(theVolRef: Integer; theDirID: Longint; VAR theWDRefNum: Integer): OsErr;
- function AskUser(thePrintPtr: MyPrintPtr): OsErr;
- procedure ModifyScalePort(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point);
- procedure ModifyScalePoint(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR thePoint: Point);
- procedure GetNewPenLoc(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR thePoint: Point);
- procedure ModifyScaleRect(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR theRect: Rect);
- procedure ModifyScalerRect(scaleRatio: Longint; VAR ovalWidth, ovalHeight: Integer);
- procedure ModifyScalePoly(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR thePoly: PolyHandle);
- procedure ModifyScaleRgn(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR theRgn: RgnHandle);
- function AdjustToInteger(theLong: Longint): Integer;
-
- implementation
-
- const
- PrintErr= $944;
-
- type
- IntPtr= ^Integer;
-
- function DraftPrOpenDoc(hPrint: THPrint; pPrPort: TPPrPort; pIOBuf: Ptr): TPPrPort;
- { here we do some allocations, get some init values and most important: modify the bottleneck }
- var
- myPPrPort: TPPrPort;
- CodeErr: Integer;
- theWorld: SysEnvRec;
- withPicComments: Boolean;
-
- procedure BugOut(theErr: Integer);
- { if something goes wrong, we must try to dispose as many blocks as we can }
- { before returning the error code }
- begin
- if myPPrPort <> nil then
- begin
- if myPPrPort^.lGParam4 <> 0 then
- begin
- if not (hPrint^^.printX[8] = 0) then
- DisposPtr(Ptr(MyPrintPtr(myPPrPort^.lGParam4)^.OtherPort));
- DisposPtr(Ptr(myPPrPort^.lGParam4));
- if myPPrPort^.gPort.portBits.rowBytes < 0
- then CloseCPort(CGrafPtr(myPPrPort))
- else ClosePort(GrafPtr(myPPrPort));
- end;
- if myPPrPort^.fOurPtr then DisposPtr(Ptr(myPPrPort));
- end;
- IntPtr(PrintErr)^ := theErr;
- DraftPrOpenDoc := myPPrPort;
- exit(DraftPrOpenDoc);
- end;
-
- begin
- DraftPrOpenDoc := nil;
- if pPrPort = nil then { does the caller give us a Printing Port or do we allocate it ? }
- begin
- myPPrPort := TPPrPort(NewPtr(sizeof(TPrPort)));
- if myPPrPort = nil then BugOut(iMemFullErr);
- myPPrPort^.fOurPtr := true;
- end
- else
- begin
- myPPrPort := pPrPort;
- myPPrPort^.fOurPtr := false;
- end;
- myPPrPort^.lGParam4 := Longint(NewPtr(sizeof(MyPrintRec))); { we need this space to work }
- if myPPrPort^.lGParam4 = 0 then BugOut(iMemFullErr);
-
- withPicComments := (hPrint^^.printX[17] = 0);
- CodeErr := SysEnvirons(1, theWorld);
-
- { the real job is here, changing the QuickDraw Bottleneck to install our printing routines }
- ChangeBottleNeck(theWorld.hasColorQD and (hPrint^^.printX[14] = 0), myPPrPort, MyPrintPtr(myPPrPort^.lGParam4), withPicComments);
-
- { to prevent any real drawing, set the bounds to EmptyRect }
- if myPPrPort^.gPort.portBits.rowBytes < 0
- then SetRect(CGrafPtr(myPPrPort)^.portPixMap^^.bounds, 0, 0, 0, 0)
- else SetRect(myPPrPort^.gPort.portBits.bounds, 0, 0, 0, 0);
- myPPrPort^.gPort.portRect := hPrint^^.prInfo.rPage;
-
- if not GetValues(hPrint, MyPrintPtr(myPPrPort^.lGParam4)) then BugOut(iMemFullErr);
-
- { if PICT saving, create another grafport to construct the picture }
- { this other port will get the same fields as the Printing Port except for the 4 last fields }
- { which are really private to each port }
- if not (hPrint^^.printX[8] = 0) then
- begin
- MyPrintPtr(myPPrPort^.lGParam4)^.OtherPort := GrafPtr(NewPtr(sizeof(GrafPort)));
- if MyPrintPtr(myPPrPort^.lGParam4)^.OtherPort = nil then BugOut(iMemFullErr);
- BlockMove(Ptr(myPPrPort), Ptr(MyPrintPtr(myPPrPort^.lGParam4)^.OtherPort), sizeof(GrafPort)-16);
- end;
-
- { we ask the user where he wants to store the printing, in a file if it's TEXT saving, }
- { in a folder if it's PICT saving }
- CodeErr := AskUser(MyPrintPtr(myPPrPort^.lGParam4));
- if CodeErr <> noErr then BugOut(CodeErr);
-
- DraftPrOpenDoc := myPPrPort;
- end;
-
- procedure DraftPrCloseDoc(pPrPort: TPPrPort);
- { pretty simple: we close everything, dispose what needs to, and that's all folks }
- var
- CodeErr: Integer;
- theWDBlock: WDPBRec;
-
- begin
- if pPrPort <> nil then
- begin
- if pPrPort^.lGParam4 <> 0 then
- begin
- if not MyPrintPtr(pPrPort^.lGParam4)^.textOrPict then
- begin
- if MyPrintPtr(pPrPort^.lGParam4)^.thePictType = 'RSED' then { • New ! v.1.1 • }
- CloseResFile(MyPrintPtr(pPrPort^.lGParam4)^.fileRef);
- DisposPtr(Ptr(MyPrintPtr(pPrPort^.lGParam4)^.OtherPort));
- with theWDBlock do
- begin
- ioCompletion := nil;
- ioVRefNum := MyPrintPtr(pPrPort^.lGParam4)^.dirVol;
- CodeErr := PBCloseWD(@theWDBlock, false);
- if CodeErr <> noErr then
- {*** This should never happen so I don't know what to do ***};
- end;
- end
- else CodeErr := FSClose(MyPrintPtr(pPrPort^.lGParam4)^.fileRef);
- DisposPtr(Ptr(pPrPort^.lGParam4));
- end
- else;
- if pPrPort^.gPort.portBits.rowBytes < 0
- then CloseCPort(CGrafPtr(pPrPort))
- else ClosePort(GrafPtr(pPrPort));
- DisposPtr(Ptr(pPrPort));
- end
- else;
- end;
-
- procedure DraftPrOpenPage(pPrPort: TPPrPort; pPageFrame: TPRect);
- { in case of PICT saving, we create a new PICT file for each page }
- { the name of the PICT file is the name chosen by the user + the number of the page }
- { and we store that file in the folder with the same name that we created in DraftPrOpenDoc }
- var
- i, CodeErr: Integer;
- val, theCount: Longint;
- nStr: Str255;
-
- begin
- with MyPrintPtr(pPrPort^.lGParam4)^ do if not textOrPict then
- begin
- CurPage := CurPage + 1;
- if thePictType <> 'RSED' then { • New ! v.1.1 • }
- begin
- { let's get the file }
- fileName := dirName;
- if Length(fileName) > 22 then fileName[0] := Chr(22);
- NumToString(CurPage, nStr);
- while Length(nStr) < 4 do nStr := Concat('0', nStr);
- if Length(nStr) = 4 then nStr := Concat(' ', nStr);
- fileName := Concat(fileName, nStr);
- CodeErr := Create(fileName, dirVol, thePictType, 'PICT');
- CodeErr := FSOpen(fileName, dirVol, fileRef);
- { as always, a PICT file begins with 512 bytes that we can set to 0 }
- theCount := 4;
- val := 0;
- for i := 1 to 128 do CodeErr := FSWrite(fileRef, theCount, @val);
- end;
- { let's reinitialize the picture saving grafport and open the picture for saving }
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- with OtherPort^ do
- begin
- picSave := nil; rgnSave := nil; polySave := nil; grafProcs := nil;
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- thePict := OpenPicture(portRect);
- if thePict = nil then
- begin
- IntPtr(PrintErr)^ := iMemFullErr;
- exit(DraftPrOpenPage);
- end;
- ClipRect(portRect);
- end;
- end;
- SetPort(GrafPtr(pPrPort));
- end;
-
- procedure DraftPrClosePage(pPrPort: TPPrPort);
- { in case of PICT saving, we close the picture and save it in the file that we close just after }
- { we also save the current color table as a 'clut' resource in the same file since a lot of }
- { Color Paint or Draw software use that kind of information to get the colors right }
- { in case of TEXT saving, we just insert an ASCII code 12 meaning Form Feed in the TEXT file }
- var
- CodeErr: Integer;
- theCount: Longint;
- aHandle: Handle;
- aVol: Integer;
-
- begin
- with MyPrintPtr(pPrPort^.lGParam4)^ do if not textOrPict then
- begin
- SetPort(OtherPort);
- ClosePicture;
- SetPort(GrafPtr(pPrPort));
- theCount := GetHandleSize(Handle(thePict));
- if thePictType = 'RSED' then { • New ! v.1.1 • }
- begin
- aVol := CurResFile;
- UseResFile(fileRef);
- AddResource(Handle(thePict), 'PICT', CurPage, '');
- WriteResource(Handle(thePict));
- UpdateResFile(fileRef);
- UseResFile(aVol);
- end
- else
- begin
- CodeErr := FSWrite(fileRef, theCount, Ptr(thePict^));
- CodeErr := FSClose(fileRef);
- if pPrPort^.gPort.portBits.rowBytes < 0 then
- begin
- CodeErr := GetVol(nil, aVol);
- CodeErr := SetVol(nil, dirVol);
- CreateResFile(fileName);
- fileRef := OpenResFile(fileName);
- if fileRef = -1 then exit(DraftPrClosePage);
- theCount := GetHandleSize(Handle(CGrafPtr(pPrPort)^.portPixMap^^.pmTable));
- aHandle := NewHandle(theCount);
- if aHandle = nil then exit(DraftPrClosePage);
- BlockMove(Ptr(CGrafPtr(pPrPort)^.portPixMap^^.pmTable^), aHandle^, theCount);
- AddResource(aHandle, 'clut', 256, '');
- CloseResFile(fileRef);
- CodeErr := SetVol(nil, aVol);
- end;
- end;
- end
- else
- begin
- CodeErr := $0C0C;
- theCount := 1;
- CodeErr := FSWrite(fileRef, theCount, @CodeErr);
- end;
- end;
-
- { And now we begin the real down to earth job starting with… }
-
- procedure DraftPrText(byteCount: Integer; textBuf: Ptr; numer, denom: Point);
- { in case of TEXT saving, we just write the incoming text and we insert an ASCII code 13 meaning }
- { Carriage Return afterwards }
- { in case of PICT saving, we just call DrawText but in the picture saving grafport, after modifying, }
- { if need be, some grafport fields with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
- CodeErr: Integer;
- theCount: Longint;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^ do if textOrPict then
- begin
- theCount := byteCount;
- CodeErr := FSWrite(fileRef, theCount, textBuf);
- CodeErr := $0D0D;
- theCount := 1;
- CodeErr := FSWrite(fileRef, theCount, @CodeErr);
- end
- else
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- DrawText(textBuf, 0, byteCount);
- SetPort(GrafPtr(pPrPort));
- GetNewPenLoc(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, pPrPort^.gPort.pnLoc);
- {to set the pen location correctly}
- end;
- end;
-
- procedure DraftPrLine(newPt: Point);
- { in case of PICT saving, we just call LineTo but in the picture saving grafport, after modifying, }
- { if need be, some grafport fields with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- ModifyScalePoint(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, newPt);
- LineTo(newPt.h, newPt.v);
- SetPort(GrafPtr(pPrPort));
- GrafPtr(pPrPort)^.pnLoc := newPt; {to set the pen location correctly}
- end;
- end;
-
- procedure DraftPrRect(verb: GrafVerb; r: Rect);
- { in case of PICT saving, we just call the right “Rect” trap depending on the verb }
- { but in the picture saving grafport, after modifying, if need be, }
- { some grafport fields with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- ModifyScaleRect(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, r);
- case verb of
- frame: FrameRect(r);
- paint: PaintRect(r);
- erase: EraseRect(r);
- invert: InvertRect(r);
- fill: FillRect(r, fillPat);
- end;
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- procedure DraftPrrRect(verb: GrafVerb; r: Rect; ovalWidth, ovalHeight: Integer);
- { in case of PICT saving, we just call the right “rRect” trap depending on the verb }
- { but in the picture saving grafport, after modifying, if need be, }
- { some grafport fields with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- ModifyScaleRect(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, r);
- ModifyScalerRect(scaleRatio, ovalWidth, ovalHeight);
- case verb of
- frame: FrameRoundRect(r, ovalWidth, ovalHeight);
- paint: PaintRoundRect(r, ovalWidth, ovalHeight);
- erase: EraseRoundRect(r, ovalWidth, ovalHeight);
- invert: InvertRoundRect(r, ovalWidth, ovalHeight);
- fill: FillRoundRect(r, ovalWidth, ovalHeight, fillPat);
- end;
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- procedure DraftPrOval(verb: GrafVerb; r: Rect);
- { in case of PICT saving, we just call the right “Oval” trap depending on the verb }
- { but in the picture saving grafport, after modifying, if need be, }
- { some grafport fields with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- ModifyScaleRect(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, r);
- case verb of
- frame: FrameOval(r);
- paint: PaintOval(r);
- erase: EraseOval(r);
- invert: InvertOval(r);
- fill: FillOval(r, fillPat);
- end;
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- procedure DraftPrArc(verb: GrafVerb; r: Rect; startAngle, arcAngle: Integer);
- { in case of PICT saving, we just call the right “Arc” trap depending on the verb }
- { but in the picture saving grafport, after modifying, if need be, }
- { some grafport fields with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- ModifyScaleRect(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, r);
- case verb of
- frame: FrameArc(r, startAngle, arcAngle);
- paint: PaintArc(r, startAngle, arcAngle);
- erase: EraseArc(r, startAngle, arcAngle);
- invert: InvertArc(r, startAngle, arcAngle);
- fill: FillArc(r, startAngle, arcAngle, fillPat);
- end;
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- procedure DraftPrPoly(verb: GrafVerb; Poly: PolyHandle);
- { in case of PICT saving, we just call the right “Poly” trap depending on the verb }
- { but in the picture saving grafport, after modifying, if need be, some grafport fields }
- { and the Poly itself with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- ModifyScalePoly(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, Poly);
- case verb of
- frame: FramePoly(Poly);
- paint: PaintPoly(Poly);
- erase: ErasePoly(Poly);
- invert: InvertPoly(Poly);
- fill: FillPoly(Poly, fillPat);
- end;
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- procedure DraftPrRgn(verb: GrafVerb; Rgn: RgnHandle);
- { in case of PICT saving, we just call the right “Rgn” trap depending on the verb }
- { but in the picture saving grafport, after modifying, if need be, some grafport fields }
- { and the Rgn itself with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- ModifyScaleRgn(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, Rgn);
- case verb of
- frame: FrameRgn(Rgn);
- paint: PaintRgn(Rgn);
- erase: EraseRgn(Rgn);
- invert: InvertRgn(Rgn);
- fill: FillRgn(Rgn, fillPat);
- end;
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- procedure DraftPrBits(var srcBits: BitMap; var srcRect, dstRect: Rect; mode: Integer; maskRgn: RgnHandle);
- { in case of PICT saving, we just call CopyBits but in the picture saving grafport, after modifying, }
- { if need be, some grafport fields with the scaling ratio chosen by the user in the options dialog }
- var
- pPrPort: TPPrPort;
- aRect: Rect;
-
- aStr: Str255;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- ModifyScalePort(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft);
- aRect := dstRect;
- ModifyScaleRect(OtherPort, scaleRatio, pPrPort^.gPort.portRect.topLeft, aRect);
- CopyBits(srcBits, portBits, srcRect, aRect, mode, maskRgn);
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- procedure DraftPrComment(kind, dataSize: Integer; dataHandle: Handle);
- { in case of PICT saving, we just call PicComment but in the picture saving grafport, }
- { and only if the user chose to save the PicComments in the options dialog }
- { Beware: some software do weird things with PicComments and with those, the PICT file is }
- { “correct” only if the user disable the PicComment saving }
- var
- pPrPort: TPPrPort;
-
- begin
- GetPort(GrafPtr(pPrPort));
- with MyPrintPtr(pPrPort^.lGParam4)^, OtherPort^ do if not textOrPict then
- begin
- BlockMove(Ptr(pPrPort), Ptr(OtherPort), sizeof(GrafPort)-16);
- SetPort(OtherPort);
- PicComment(kind, dataSize, dataHandle);
- SetPort(GrafPtr(pPrPort));
- end;
- end;
-
- { That's all for the down to earth job ! }
-
- procedure ChangeBottleNeck(withColor: Boolean; myPPrPort: TPPrPort; thePrintPtr: MyPrintPtr; withPicComments: Boolean);
- { here we actually replace the standard QuickDraw bottleneck routines by ours }
- procedure SetPrgProcs;
- begin
- myPPrPort^.gProcs.textProc := @DraftPrText;
- myPPrPort^.gProcs.lineProc := @DraftPrLine;
- myPPrPort^.gProcs.rectProc := @DraftPrRect;
- myPPrPort^.gProcs.rRectProc := @DraftPrrRect;
- myPPrPort^.gProcs.ovalProc := @DraftPrOval;
- myPPrPort^.gProcs.arcProc := @DraftPrArc;
- myPPrPort^.gProcs.polyProc := @DraftPrPoly;
- myPPrPort^.gProcs.rgnProc := @DraftPrRgn;
- myPPrPort^.gProcs.bitsProc := @DraftPrBits;
- if withPicComments then myPPrPort^.gProcs.commentProc := @DraftPrComment;
- end;
- begin
- with thePrintPtr^ do if withColor then
- begin
- OpenCPort(CGrafPtr(myPPrPort));
- SetStdCProcs(cProcs);
-
- { even with a Color PICT saving, we set the gProcs field of the Printing port }
- { just in case some weird application wants to use them directly }
- { to my knowledge, no application do such an absurd thing as that but Murphy Lives ! }
- SetPrgProcs;
-
- cProcs.textProc := @DraftPrText;
- cProcs.lineProc := @DraftPrLine;
- cProcs.rectProc := @DraftPrRect;
- cProcs.rRectProc := @DraftPrrRect;
- cProcs.ovalProc := @DraftPrOval;
- cProcs.arcProc := @DraftPrArc;
- cProcs.polyProc := @DraftPrPoly;
- cProcs.rgnProc := @DraftPrRgn;
- cProcs.bitsProc := @DraftPrBits;
- if withPicComments then cProcs.commentProc := @DraftPrComment;
- CGrafPtr(MyPPrPort)^.grafProcs := @cProcs;
- end
- else
- begin
- OpenPort(GrafPtr(myPPrPort));
- SetStdProcs(myPPrPort^.gProcs);
- SetPrgProcs;
- myPPrPort^.gPort.grafProcs := @myPPrPort^.gProcs;
- end;
- end;
-
- function GetValues(hPrint: THPrint; thePrintPtr: MyPrintPtr): Boolean;
- { let's transfer some values from resources or hPrint to my sapce work for commodity }
- var
- aStrHdl: StringHandle;
-
- begin
- GetValues := true;
- aStrHdl := GetString(-8191);
- if aStrHdl = nil then
- begin
- GetValues := false;
- exit(GetValues);
- end;
- thePrintPtr^.fileName := aStrHdl^^;
- with thePrintPtr^ do
- begin
- BlockMove(@hPrint^^.printX[10], @theTextType, 4);
- BlockMove(@hPrint^^.printX[12], @thePictType, 4);
- BlockMove(@hPrint^^.printX[15], @scaleRatio, 4);
- textOrPict := (hPrint^^.printX[8] = 0);
- end;
- end;
-
- function GetVolumeRef(theWDRefNum: Integer; VAR theVolRef: Integer; VAR theDirID: Longint): OsErr;
- { 'nuff said ! }
- var
- theWDBlock: WDPBRec;
- aStr: Str255;
-
- begin
- with theWDBlock do
- begin
- ioCompletion := nil;
- ioNamePtr := @aStr;
- ioVRefNum := theWDRefNum;
- ioWDIndex := 0;
- ioWDProcID := 0;
- ioWDVRefNum := 0;
- GetVolumeRef := PBGetWDInfo(@theWDBlock, false);
- theVolRef := ioWDVRefNum;
- theDirID := theWDBlock.ioWDDirID;
- end;
- end;
-
- function CreateDirectory(VAR fName: Str63; theVRefNum: Integer; theDirID: Longint; VAR theNewDirID: Longint): OsErr;
- { 'nuff saif ! }
- var
- theHBlock: HParamBlockRec;
-
- begin
- with theHBlock do
- begin
- ioCompletion := nil;
- ioNamePtr := @fName;
- ioVRefNum := theVRefNum;
- ioDirID := theDirID;
- CreateDirectory := PBDirCreate(@theHBlock, false);
- theNewDirID := theHBlock.ioDirID;
- end;
- end;
-
- function OpenWorkingDirectory(theVolRef: Integer; theDirID: Longint; VAR theWDRefNum: Integer): OsErr;
- { 'nuff said ! }
- var
- theWDBlock: WDPBRec;
-
- begin
- with theWDBlock do
- begin
- ioCompletion := nil;
- ioNamePtr := nil;
- ioVRefNum := theVolRef;
- ioWDProcID := 0;
- ioWDDirID := theDirID;
- OpenWorkingDirectory := PBOpenWD(@theWDBlock, false);
- theWDRefNum := theWDBlock.ioVRefNum;
- end;
- end;
-
- function AskUser(thePrintPtr: MyPrintPtr): OsErr;
- { always ask user (heh ! heh ! heh !) }
- { in case of TEXT saving, we just create a TEXT file with the name chosen }
- { in case of PICT saving, we just create a folder with the name chosen and we open that directory }
-
- { • New ! v.1.1 • if the requested PICT creator is 'RSED' (ResEdit), we create a resource file }
- { in which we will store the pictures as PICT resources }
- var
- thePoint: Point;
- theReply: SFReply;
- CodeErr: OsErr;
- theDirID: Longint;
- theVolRef: Integer;
-
- procedure BugOut;
- begin AskUser := CodeErr; exit(AskUser); end;
-
- begin
- AskUser := noErr;
- with thePrintPtr^, theReply do
- begin
- thePoint.h := 50; thePoint.v := 50;
- SFPutFile(thePoint, '', fileName, nil, theReply);
- if good then
- begin
- if textOrPict or (thePictType = 'RSED') then { • New ! v.1.1 • }
- begin
- CodeErr := FSDelete(fName, vRefNum);
- if textOrPict { • New ! v.1.1 • }
- then CodeErr := Create(fName, vRefNum, theTextType, 'TEXT')
- else CodeErr := Create(fName, vRefNum, 'RSED', 'rsrc');
- if CodeErr <> noErr then BugOut;
- if textOrPict then { • New ! v.1.1 • }
- CodeErr := FSOpen(fName, vRefNum, fileRef)
- else
- begin
- CodeErr := SetVol(nil, vRefNum);
- CreateResFile(fName);
- fileRef := OpenResFile(fName);
- if fileRef = -1 then CodeErr := ResError;
- CurPage := 0;
- end;
- if CodeErr <> noErr then BugOut;
- dirVol := vRefNum;
- end
- else
- begin
- CodeErr := GetVolumeRef(vRefNum, theVolRef, theDirID);
- if CodeErr <> noErr then BugOut;
- CodeErr := CreateDirectory(fName, vRefNum, theDirID, dirID);
- if CodeErr <> noErr then BugOut;
- CodeErr := OpenWorkingDirectory(theVolRef, dirID, dirVol);
- if CodeErr <> noErr then BugOut;
- dirName := fName;
- CurPage := 0;
- end;
- fileName := fName;
- end
- else AskUser := iPrAbort;
- end;
- end;
-
- function AdjustToInteger(theLong: Longint): Integer;
- { let's trunc the Longint to an Integer }
- begin
- if theLong > 32767 then AdjustToInteger := 32767
- else if theLong < $FFFF8000 then AdjustToInteger := $8000
- else AdjustToInteger := theLong;
- end;
-
- procedure ModifyScalePort(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point);
- { apply the scaling ratio to the right fields of the grafport }
- var
- aRect: Rect;
-
- begin
- with OtherPort^, portRect, topLeft do
- begin
- top := AdjustToInteger((scaleRatio * top) div 100);
- left := AdjustToInteger((scaleRatio * left) div 100);
- bottom := AdjustToInteger((scaleRatio * bottom) div 100);
- right := AdjustToInteger((scaleRatio * right) div 100);
- SetRect(aRect, -32767, -32767, 32767, 32767);
- RectRgn(visRgn, aRect);
- RectRgn(clipRgn, aRect);
- pnLoc.h := AdjustToInteger((scaleRatio * (pnLoc.h - h)) div 100 + left);
- pnLoc.v := AdjustToInteger((scaleRatio * (pnLoc.v - v)) div 100 + top);
- pnSize.h := AdjustToInteger((scaleRatio * pnSize.h) div 100);
- pnSize.v := AdjustToInteger((scaleRatio * pnSize.v) div 100);
- txSize := AdjustToInteger((scaleRatio * txSize) div 100);
- end;
- end;
-
- procedure ModifyScalePoint(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR thePoint: Point);
- begin
- with OtherPort^.portRect, topLeft do
- begin
- thePoint.h := AdjustToInteger((scaleRatio * (thePoint.h - h)) div 100 + left);
- thePoint.v := AdjustToInteger((scaleRatio * (thePoint.v - v)) div 100 + top);
- end;
- end;
-
- procedure GetNewPenLoc(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR thePoint: Point);
- begin
- with OtherPort^, portRect, topLeft do
- begin
- thePoint.h := AdjustToInteger((Longint(100) * (pnLoc.h - left)) div scaleRatio + h);
- thePoint.v := AdjustToInteger((Longint(100) * (pnLoc.v - top)) div scaleRatio + v);
- end;
- end;
-
- procedure ModifyScaleRect(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR theRect: Rect);
- begin
- with OtherPort^.portRect, topLeft do
- begin
- theRect.top := AdjustToInteger((scaleRatio * (theRect.top - v)) div 100 + top);
- theRect.left := AdjustToInteger((scaleRatio * (theRect.left - h)) div 100 + left);
- theRect.bottom := AdjustToInteger((scaleRatio * (theRect.bottom - v)) div 100 + top);
- theRect.right := AdjustToInteger((scaleRatio * (theRect.right - h)) div 100 + left);
- end;
- end;
-
- procedure ModifyScalerRect(scaleRatio: Longint; VAR ovalWidth, ovalHeight: Integer);
- begin
- ovalWidth := AdjustToInteger((scaleRatio * ovalWidth) div 100);
- ovalHeight := AdjustToInteger((scaleRatio * ovalHeight) div 100);
- end;
-
- procedure ModifyScalePoly(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR thePoly: PolyHandle);
- var
- theLength, pos: Longint;
- aPoint: Point;
-
- begin
- with OtherPort^.portRect, topLeft, thePoly^^ do
- begin
- ModifyScaleRect(OtherPort, scaleRatio, topLeft, polyBBox);
- theLength := GetHandleSize(Handle(thePoly));
- pos := 10;
- while pos < theLength do
- begin
- BlockMove(Ptr(Longint(thePoly^)+pos), @aPoint, 4);
- ModifyScalePoint(OtherPort, scaleRatio, topLeft, aPoint);
- BlockMove(@aPoint, Ptr(Longint(thePoly^)+pos), 4);
- pos := pos+4;
- end;
- end;
- end;
-
- procedure ModifyScaleRgn(OtherPort: GrafPtr; scaleRatio: Longint; topLeft: Point; VAR theRgn: RgnHandle);
- var
- theLength: Longint;
- aHandle: Handle;
- dh, dv, delh, delv: Integer;
- aPoint: Point;
-
- begin
- theLength := GetHandleSize(Handle(theRgn));
- aHandle := NewHandle(2 * theLength); {cf IM I-184 for explanation}
- if aHandle <> nil then
- begin
- DisposHandle(aHandle);
- aPoint := theRgn^^.rgnBBox.topLeft;
- ModifyScalePoint(OtherPort, scaleRatio, topLeft, aPoint);
- dh := aPoint.h - theRgn^^.rgnBBox.left;
- dv := aPoint.v - theRgn^^.rgnBBox.top;
- OffsetRgn(theRgn, dh, dv);
-
- dh := theRgn^^.rgnBBox.right - theRgn^^.rgnBBox.left;
- dv := theRgn^^.rgnBBox.bottom - theRgn^^.rgnBBox.top;
- delh := AdjustToInteger((scaleRatio * dh) div 100);
- delv := AdjustToInteger((scaleRatio * dv) div 100);
- InsetRgn(theRgn, dh-delh, dv-delv);
- OffsetRgn(theRgn, (delh - dh) div 2, (delv -dv) div 2);
- end;
- end;
-
- end.
-